package com.king.juc.syncmode;

import java.util.concurrent.locks.LockSupport;

/**
 * Park/unpark 交替输出案例
 * @author king
 * @date 2020/11/23 16:52
 */
public class ParkUnpark {
    private int loopNumber;

    public ParkUnpark(int loopNumber) {
        this.loopNumber = loopNumber;
    }

    public void print(String str, Thread next){
        for (int i = 0; i < loopNumber; i++) {
            LockSupport.park();
            System.out.print(str);
            LockSupport.unpark(next);
        }
    }
}
